Value Extension Traits
Extension trait for working with JSON values in a more convenient way.
JsonValueExt
offers convenient methods for interacting with serde_json::Value
objects,
simplifying tasks like getting, taking, inserting, traversing, and pretty-printing JSON data
while ensuring type safety with Serde's serialization and deserialization.
Provided Methods
x_get
: Returns a value of a specified typeT
from a JSON object using either a direct name or a pointer path.x_take
: Takes a value from a JSON object using a specified name or pointer path, replacing it withNull
.x_insert
: Inserts a value of typeT
into a JSON object at the specified name or pointer path, creating any missing objects along the way.x_walk
: Traverses all properties within the JSON value tree, applying a user-provided callback function on each property.x_pretty
: Returns a pretty-printed string representation of the JSON value.
Usage
This trait is intended to be used with serde_json::Value
objects. It is particularly
useful when you need to manipulate JSON structures dynamically or when the structure
of the JSON is not known at compile time.
use ;
use DeserializeOwned;
use Serialize;
use JsonValueExt;
This trait enhances the serde_json::Value
API by adding more type-safe and convenient
methods for manipulating JSON data in Rust.